/*
 * 百度在线网络技术（北京）有限公司拥有本软件版权2020并保留所有权利。
 * Copyright 2020, Baidu.com,Inc 2:Baidu Online Network Technology (Beijing) Co.,Ltd,
 * All rights reserved.
 */

package com.azdebugit.concurrent;

import java.util.Random;
import java.util.concurrent.CountDownLatch;  
import java.util.concurrent.TimeUnit;  
  
public class Worker implements Runnable{
    private CountDownLatch downLatch;  
    private String name;
    public Worker(CountDownLatch downLatch, String name){  
        this.downLatch = downLatch;  
        this.name = name;  
    }
    public void run() {  
        this.doWork();  
        try{  
            TimeUnit.SECONDS.sleep(new Random().nextInt(10));  
        }catch(InterruptedException ie){  
        }  
        System.out.println(this.name + "活干完了！");  
        this.downLatch.countDown();
    }
    private void doWork(){  
        System.out.println(this.name + "正在干活!");  
    }  
      
}  